// subpages1/protectRight/protectRight.js
const app = getApp();
Page({

  data: {
    pageData:{id:0},  //页面参数，维权id
    rightInfo:{},     //维权信息
  },

  onLoad: function (options) {
    this.setData({"pageData.id":options.id});
    this.getList();
  },

  onShow: function () {

  },
  // 拉取维权信息
  getList(){
    let that = this;
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      mask: true,
      duration: 10000
    });
    wx.request({
      url: app.globalData.requestUrl+`&map=applet_single_refund_record&id=${this.data.pageData.id}`,
      method:"GET",
      success(res){
        console.log('退款记录',res)
        if (res.data.ec == 200) {
          res.data.data.tr_goods_data.forEach(v=>{
            let total = 0;
            v.ticket_info.forEach(k=>{
              total+=Number(k.cr_ticket_price);
            })
            v.subTotal = total.toFixed(2);   //小计
            v.cover = v.cover.includes("http")? v.cover : "http://shopping.zhjl.link"+v.cover;
          })
          that.setData({
            rightInfo: res.data.data
          })
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.em,
            showCancel: false
          });
        }
      },
      complete: function () {
        wx.hideToast();
      }
    })
  },
  //撤销维权
  cancelRight(e){
    var that = this;
    var tid = e.target.dataset.tid;
    wx.showModal({
      title: '',
      cancelText: '再考虑下',
      confirmText: '确认',
      content: '确认撤销维权吗？',
      confirmColor: '#1AAD16',
      success: function (res) {
        if (res.confirm) {
          //发起请求，获取列表列表
          wx.showToast({
            title: '加载中',
            icon: 'loading',
            mask: true,
            duration: 10000
          });
          wx.request({
            url: app.globalData.requestUrl,
            data: {
              map: 'applet_order_refund_cancel',
              // suid: app.globalData.suid,
              tid: tid
            },
            success: function (res) {
              if (res.data.ec == 200) {
                setTimeout(wx.showToast,0,{
                  title: '撤销成功！',
                  duration:1500
                });
                setTimeout(wx.navigateBack,1500);
              } else {
                wx.showModal({
                  title: '提示',
                  content: res.data.em,
                  showCancel: false
                });
              }
            },
            complete: function () {
              wx.hideToast();
            }
          });
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
})